package com.baijiaoxi.utils.qcloud;

import java.io.File;
import java.io.InputStream;
import java.util.Date;

public interface OSHelper extends AutoCloseable {

    long partSize = 1 * 1024 * 1024;//分块大小为1m
    long partLimit = 10 * 1024 * 1024;//文件大于10m使用分块上传

    void close();

    boolean isShutdownAfterUseStat(); //是否需要在使用后立即关闭

    OSHelper setShutdownAfterUseStat(boolean shutdownAfterUseStat); //是否需要在使用后立即关闭

    String getSignUploadUrl(String fileKey, String contentType, boolean shutdownAfterUseStat);

    default String getSignUploadUrl(String fileKey, String contentType) {
        return getSignUploadUrl(fileKey, contentType, isShutdownAfterUseStat());
    }

    /**
     * 上传
     *
     * @param key
     * @param url
     */
    default void upload(String key, String originFilename, String url, boolean shutdownAfterUseStat) {
        upload(key, originFilename, url, shutdownAfterUseStat, true);
    }

    void upload(String key, String originFilename, String url, boolean shutdownAfterUseStat, boolean addMeta);

    default void upload(String key, String originFilename, String url) {
        upload(key, originFilename, url, isShutdownAfterUseStat());
    }


    /**
     * 上传
     *
     * @param key
     * @param localFile
     */
    default void upload(String key, String originFilename, File localFile, boolean shutdownAfterUseStat) {
        upload(key, originFilename, localFile, shutdownAfterUseStat, true);
    }

    void upload(String key, String originFilename, File localFile, boolean shutdownAfterUseStat, boolean addMeta);

    default void upload(String key, String originFilename, File localFile) {
        upload(key, originFilename, localFile, isShutdownAfterUseStat());
    }

    /**
     * 上传
     *
     * @param key
     * @param localFile
     */
    default void uploadWithPart(String key, String originFilename, File localFile, boolean shutdownAfterUseStat) {
        uploadWithPart(key, originFilename, localFile, shutdownAfterUseStat, true);
    }

    void uploadWithPart(String key, String originFilename, File localFile, boolean shutdownAfterUseStat, boolean addMeta);

    default void uploadWithPart(String key, String originFilename, File localFile) {
        uploadWithPart(key, originFilename, localFile, isShutdownAfterUseStat());
    }


    /**
     * 上传
     * 流式
     *
     * @param key
     * @param inputStream
     */
    default void upload(String key, String originFilename, InputStream inputStream, boolean shutdownAfterUseStat) {
        upload(key, originFilename, inputStream, shutdownAfterUseStat, true);
    }

    void upload(String key, String originFilename, InputStream inputStream, boolean shutdownAfterUseStat, boolean addMeta);

    default void upload(String key, String originFilename, InputStream inputStream) {
        upload(key, originFilename, inputStream, isShutdownAfterUseStat());
    }

    /**
     * 获取有过期时间的链接
     *
     * @param key
     * @param expirationDate
     * @return
     */
    String getUrl(String key, Date expirationDate, boolean shutdownAfterUseStat);

    default String getUrl(String key, Date expirationDate) {
        return getUrl(key, expirationDate, isShutdownAfterUseStat());
    }

    /**
     * 删除
     *
     * @param key
     */
    void del(String key, boolean shutdownAfterUseStat);

    default void del(String key) {
        del(key, isShutdownAfterUseStat());
    }

    /**
     * 获取静态地址
     *
     * @param fileKey
     * @return
     */
    String getStaticUrl(String fileKey);

    /**
     * 获取对象信息
     *
     * @param fileKey
     * @return
     */
    ObjectInfo getObjectInfo(String fileKey, boolean shutdownAfterUseStat);

    default ObjectInfo getObjectInfo(String fileKey) {
        return getObjectInfo(fileKey, isShutdownAfterUseStat());
    }

    /**
     * 修改文件头
     *
     * @param fileKey
     * @param downloadName
     * @param cacheControl
     * @param shutdownAfterUseStat
     */

    void modifyContentType(String fileKey, String downloadName, String cacheControl, boolean shutdownAfterUseStat);

    default void modifyContentType(String fileKey, String downloadName, String cacheControl) {
        modifyContentType(fileKey, downloadName, cacheControl, isShutdownAfterUseStat());
    }

    default void clearContentDisposition(String fileKey) {
        clearContentDisposition(fileKey, isShutdownAfterUseStat());
    }

    void clearContentDisposition(String fileKey, boolean shutdownAfterUseStat);

    /**
     * 下载文件
     *
     * @param fileKey
     * @param fullLocalPath
     */
    void download(String fileKey, String fullLocalPath, boolean shutdownAfterUseStat);

    default void download(String fileKey, String fullLocalPath) {
        download(fileKey, fullLocalPath, isShutdownAfterUseStat());
    }
}
